package com.majsubtense.core.achievements;

import com.majsubtense.core.components.UI;
import com.majsubtense.core.events.EventHandler;
import com.majsubtense.core.events.GameSceneChangeEvent;

public class PressGameStartButtonAchievement extends CountTriggeredAchievement {
    public static final AchievementType<PressGameStartButtonAchievement> ANY;
    private final int maxCount = 5;

    public PressGameStartButtonAchievement() {
        super(PressGameStartButtonAchievement.ANY, "薛定谔的游戏重置键...");

        setCountGenerator(() -> count + 1);

        UI.addListener(new EventHandler<>(
                GameSceneChangeEvent.ANY,
                gameSceneChangeEvent -> {
                    if (gameSceneChangeEvent.getChangeTo().equals("RaceVenue"))
                        count = countGenerator.generate();
                    if (count == maxCount)
                        finishAchievement();
                }
        ));
    }

    @Override
    public void finishAchievement() {
        if (!isFinished()) {
            AchievementController.showAchievementDialog(this);
            setFinished(true);
        }
    }

    static {
        ANY = new AchievementType<>(CountTriggeredAchievement.ANY, "PRESS_GAME_START_BUTTON");
    }
}
